package io.osw.modules.sys.task;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.osw.modules.sys.entity.TestUserEntity;
import io.osw.modules.sys.service.TestUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@EnableScheduling
@Configuration
public class UpdateUserTask {

    @Autowired
    private TestUserService testUserService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Scheduled(cron = "0 25 16 * * ?")
    public void update(){
        logger.info(" \n==================== 开始执行, 更新用户信息 =========================");
        EntityWrapper<TestUserEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("phone","13333333333");
        TestUserEntity testUser = testUserService.selectOne(wrapper);
        if(testUser!=null){
            testUser.setAddress("河南禹州");
            //根据ID更新 没有传值的属性不会更新
            testUserService.updateById(testUser);
        }
        logger.info(" \n==================== 开始执行, 更新完成 =========================");
    }
}
